package com.坦克大战.Tank_3;

import java.util.Vector;

public class EnemyTanks extends Tank implements Runnable{ ///敌人坦克
    Vector<Shoot> EnemyTanksBullets  = new Vector<>();  ///敌人坦克集合
    boolean isLive = true;  ///生命状态
    public EnemyTanks(int x, int y, int speed) {
        super(x, y, speed);
        setDirection(2);///初始化方向为下
    }

    @Override
    public void run() {
        while (isLive) {   /// 如果坦克死亡就结束线程
            int direction = (int) (Math.random() * 4);  ///随机4个方向
            int move = (int) (Math.random() * 30);      ///按一个方向随机移动0~30之间的步
            switch (direction) {
                case 0:
                    for (int i = 0; i < move; i++) {
                        moveUP();
                        sleep();
//                        System.out.println(num + "  "+getX() + "   " + getY());
                    }
                    break;
                case 1:
                    for (int i = 0; i < move; i++) {
                        moveLEFT();
                        sleep();
//                        System.out.println(num + "  "+getX() + "   " + getY());
                    }
                    break;
                case 2:
                    for (int i = 0; i < move; i++) {
                        moveDOWN(700);
                        sleep();
//                        System.out.println(num + "  "+getX() + "   " + getY());
                    }
                    break;
                case 3:
                    for (int i = 0; i < move; i++) {
                        moveRIGHT(1500);
                        sleep();
//                        System.out.println(num + "  "+getX() + "   " + getY());
                    }
                    break;
            }

            /// 每次转向停顿一下，符合惯性
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }


        }
    }
    /// 睡眠方法，防止移动速度非常快
    void sleep(){
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }

}
